package com.luzhikun.filters;

import javax.servlet.*;
import java.io.IOException;

/*
 * @Author liu-miss
 * @Description字符编码过滤器
 * @Date 17:42 2021/5/4
 *
 * 解决POST中文乱码问题 对GET方式不起作用
 **/
public class CharactorFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        // 解决请求传过来的参数的中文乱码问题
        request.setCharacterEncoding("UTF-8");

        // 解决响应传出的参数的中文乱码问题
        response.setContentType("text/html;charset=UTF-8");
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
